package com.yboot.starter.shiro.core.realm;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthenticatingRealm;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.stereotype.Component;

/**
 * 功能描述
 *
 * @author yangcs
 * @date 2025/8/20
 */
@Component
public class SmsCodeRealm extends AuthenticatingRealm {
    @Override
    public boolean supports(AuthenticationToken token) {
        // 只处理SmsCodeToken
        return token instanceof SmsCodeToken;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        SmsCodeToken smsToken = (SmsCodeToken) token;
        // ... 手机验证码认证逻辑
        // 比如，从Redis中获取验证码进行比对
        //@TODO 组装用户
        AuthenticationInfo authcInfo = new SimpleAuthenticationInfo("userDTO", "credentials", getName());
        return authcInfo;
    }
}
